var aaa ="#fUI/UIWindow.img/PvP/Scroll/enabled/next2#";
var status = 0;
var typed=0;
var rmb = 0;
var weaponId = null;
var finalItem;
var finalItemQuantity;
var finalItemCost;
/*兑换材料var needItemList = Array(
    
    4002000
     
);*/

var exchangeList = Array(
    //兑换列表：ID，兑换获得数量，需要邮票数量
    Array(4001832,50,1),//咒语痕迹
    Array(4001839,50,1),//星星
  
    Array(2049323,1,10),//高级装备强化卷轴
    // Array(2630161,1,20),//能手册20
    // Array(2630162,1,30),//能手册30
    Array(2023399,1,50),//荒野猎人
    Array(2022179,1,66),//玛瑙苹果
    Array(2023568,10,10),//夜光法师的发胶，领导力+300
    Array(2023567,10,10),//龙神的蒸土豆，洞察力+300
    Array(2023566,10,10),//战神的能量饮料，意志+300
    Array(2023565,10,10),//幻影的护手霜，手技+300
    Array(2023564,10,10),//隐月的意式咖啡，感性+300
    Array(2023563,10,10),//双弩精灵的唇膏，魅力+300
    Array(2433960, 1, 20),
    Array(2433961, 1, 30),
    Array(2100900,10,1)//怪物召唤包

  //Array(2000005,100,1)//超级药水

);

function start() {
    status = -1;
    action(1, 0, 0);
}


function action(mode, type, selection) {
    if (mode == -1) {
        cm.dispose();
    } else {
        if (mode == 0 && status == 0) {
			cm.dispose();
			return;
       }
       
    if (mode == 1) 
        status++;
    else
		status--;

        if (status == 0) {
            var selStr = "#d这里是蜗牛邮票兑换,更多新品请等待管理肥添加：#n#k\r\n";    
			for(var key in exchangeList) {
				var item = exchangeList[key][0];
				selStr += "#r#L"+key+"#兑换 #b#z"+item+"# #r\r\n";
			}
        	cm.sendSimple(selStr);	
    }else if (status == 1) {
        var exchangeId = selection;

        finalItem = exchangeList[exchangeId][0];
        finalItemQuantity = exchangeList[exchangeId][1];
        finalItemCost = exchangeList[exchangeId][2];

        var text = "- #e#d兑换#z"+finalItem+"#"+finalItemQuantity+"个需要的材料：#n#k\r\n\r\n#b";

            var itemName = cm.getItemName(4002000);
            text+=itemName;
            for(var i=0; i<=10-itemName.getBytes().length; i++)
            {
                text+=" ";
            }
            var currentItemQuantity = cm.getItemQuantity(4002000);
            var color="#g";
            if (currentItemQuantity<finalItemCost)
                color="#r";
            text+=color+currentItemQuantity+" / "+finalItemCost+" 个#b\r\n";
        
        text+="#k\r\n\r\n- #e#d提示：#n#b点 “是” 进行制作。点 “否” 返回上一页.#k";
        cm.sendYesNo(text);
        
    } else if (status == 2) {
       
     
       if (cm.haveItem(4002000,finalItemCost)) {
           if (cm.getSpace(2)<1) {
               cm.sendOk("消耗空间不足，请整理后重新兑换！");
               cm.dispose();

            }

            cm.gainItem(finalItem,finalItemQuantity);
            cm.gainItem(4002000,-finalItemCost);
           cm.sendOk("- #e#d兑换#z"+finalItem+"#"+finalItemQuantity+"个成功#n#k\r\n\r\n#b");
           cm.dispose();
        } else {
           cm.sendOk("材料不足，无法完成制作！");
           cm.dispose();
        }

        }
    }
}

